package org.glut.service;

import org.glut.controller.RouterController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PreDestroy;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Service
public class StartService implements ServletContextListener {
//    ExecutorService pool = Executors.newFixedThreadPool(50);
    @Autowired
    private MessageService messageService;

    /**
     * 启动的时候执行
     * @param sce
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
//        Runnable run = new Runnable() {
//            @Override
//            public void run() {
//                messageService.mesService();
//            }
//        };
//        pool.execute(run);

//        ServletContextListener.super.contextInitialized(sce);
    }

    /**
     * 退出程序执行
     * @throws Exception
     */
    @PreDestroy
    public void destory() throws Exception {
//        messageService.socket.close();
//        pool.shutdownNow();
        RouterController.pool.shutdownNow();
        System.out.println("关闭");
    }

}
